<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <%@ include file="inc/meta.jsp" %>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <%@ include file="inc/css.jsp" %>
    <%@ include file="inc/js.jsp" %>
</head>

<body class="childrenBody">
<form style="padding-top: 15px;" class="layui-form" id="uploadForm" action="backend/file/save" method="post" enctype="multipart/form-data">
    <input type="hidden" id="groupId" name="groupId"/>
    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <input style="margin-top: 6px;" type="file" lay-verify="required" name="uploadFile" id="uploadFile"/>
        </div>
    </div>

    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" lay-submit="" lay-filter="saveInfo">确定上传</button>
        </div>
    </div>
</form>
</body>

<script>
    var form;
    layui.use(['form', 'layer'], function () {
        form = layui.form;
        var layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery;

        form.on("submit(saveInfo)", function (data) {
            //弹出loading
            var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
            // 实际使用时的提交信息
            $("#uploadForm").ajaxSubmit({
                success: function (res) {
                    console.log(res);
                    if (res === 1) {
                        top.layer.close(index);
                        top.layer.msg("文件添加成功！");
                        layer.closeAll("iframe");
                        //刷新父页面
                        parent.location.reload();
                    } else {
                        top.layer.close(index);
                        top.layer.msg("文件添加失败！");
                    }
                },
                url: 'backend/file/save', /*设置post提交到的页面*/
                type: "post", /*设置表单以post方法提交*/
                dataType: "json" /*设置返回值类型为文本*/
            });
            return false;
        });
    });
</script>

</html>